package com.tuo51.evaluate.vo.users;

import com.tuo51.core.domain.org.Organization;
import com.tuo51.core.domain.staffs.Staff;
import com.tuo51.foudation.utils.CopyUtils;
import lombok.Data;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * *******************************
 * Created by Ron.
 * form com.tuo51
 * on 2017/7/18
 * *******************************
 */
@Data
public class StaffVO {

    private String id;

    private String mobile;

    private String nickName;

    private String realName;

    private String sexDesc;

    private Integer sex=0;

    private String headImgUrl;

    private String unionid;

    Object userVip;

    StaffExtInfoVO extInfo;
    Organization org;

    public static StaffVO of(Staff staff) {
        StaffVO vo = new StaffVO();

        CopyUtils.copyProperties(staff, vo);

        return vo;
    }

    public static StaffVO of(Staff staff, Organization org) {
        StaffVO vo = new StaffVO();
        vo.setMobile(staff.getMobile());
        vo.setNickName(staff.getNickName());
        vo.setRealName(staff.getRealName());
        vo.setSexDesc(staff.getSexDesc());
        vo.setSex(staff.getSex());
        vo.setHeadImgUrl(staff.getHeadImgUrl());
        vo.setExtInfo(StaffExtInfoVO.of(staff.getExtInfo(), org));
        vo.setOrg(org);
        vo.setId(staff.getId());
        vo.setUnionid(staff.getUnionid());

        //创建VIP对象
        Map userVip = new HashMap();
        userVip.put("expireTime", org.getExpireTime());
        userVip.put("restCount", org.getRestCount());

        int level = 0;
        Date now = new Date();
        if(Objects.nonNull(org) && Objects.nonNull(org.getRestCount()) && org.getRestCount() > 0){
            level += 1;
        }
        if(Objects.nonNull(org) && Objects.nonNull(org.getExpireTime()) && now.compareTo(org.getExpireTime()) == -1){
            level += 2;
        }
        userVip.put("vipLevel", level);
        vo.setUserVip(userVip);

        org.setVipLevel(level);

        return vo;
    }

}
